package guowenlong.golf.ui.dynamic.message;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import butterknife.BindView;
import butterknife.ButterKnife;
import guowenlong.golf.R;
import guowenlong.golf.base.BaseFragment;

/**
 * des   : 描述
 * author: Administrator
 * email : guowenlong20000@gmail.com
 * time  : 2017年03月26日 上午 12:30.
 */

public class MessageFragment extends BaseFragment {

  @BindView(R.id.rv_dynamic_golf)
  RecyclerView rvDynamic;
  @BindView(R.id.rv_dynamic_alliance)
  RecyclerView rvDynamicAlliance;
  @BindView(R.id.lv_dynamic_rule)
  ListView lvDynamicRule;
  private MessageGolfAdapter mMessageGolfAdapter;
  private MessageAllianceAdapter mMessageAllianceAdapter;

  @Override
  public void initData(Bundle savedInstanceState) {

  }

  @Override
  public int getLayoutId() {
    return R.layout.fragment_dynamic_message;
  }

  @Override
  public void initView() {
    initGolf();
    initAlliance();
    initListView();
  }

  private void initListView() {
    lvDynamicRule.setAdapter(new RuleAdapter());
  }

  private void initGolf() {
    //设置布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    rvDynamic.setLayoutManager(linearLayoutManager);
    //设置适配器
    mMessageGolfAdapter = new MessageGolfAdapter(getActivity());
    rvDynamic.setAdapter(mMessageGolfAdapter);
  }

  private void initAlliance() {
    //设置布局管理器
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    rvDynamicAlliance.setLayoutManager(linearLayoutManager);
    //设置适配器
    mMessageAllianceAdapter = new MessageAllianceAdapter(getActivity());
    rvDynamicAlliance.setAdapter(mMessageAllianceAdapter);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // TODO: inflate a fragment view
    View rootView = super.onCreateView(inflater, container, savedInstanceState);
    ButterKnife.bind(this, rootView);
    return rootView;
  }

  private class RuleAdapter extends BaseAdapter {

    @Override
    public int getCount() {
      return 10;
    }

    @Override
    public Object getItem(int position) {
      return null;
    }

    @Override
    public long getItemId(int position) {
      return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//      ViewHolder hodler;
//      if (convertView != null) {
//        hodler = (ViewHolder) convertView.getTag();
//        convertView.setTag(hodler);
//      } else {
//        convertView = View.inflate(getActivity(), R.layout.item_dynamic_item, null);
//        hodler = new ViewHolder(convertView);
//        convertView.setTag(hodler);
//      }
//      final PoiItem poiItem = mPoiItems.get(position);
//      hodler.itemTvNearTitle.setText(poiItem.getTitle());
//      hodler.itemTvCagatory.setText(poiItem.getBusinessArea());
//      hodler.itemLlNearGoto.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//          AMapLocation aMapLocation = ((HomeActivity) context).mMapManager.getmLocation();
//          LatLonPoint latLonPoint = mPoiItems.get(position).getLatLonPoint();
//          ((HomeActivity) context).mMapManager.startNavi(aMapLocation.getLatitude(), aMapLocation.getLongitude()
//              , latLonPoint.getLatitude(), latLonPoint.getLongitude());
//        }
//      });
//      LatLonPoint latLonPoint = poiItem.getLatLonPoint();
//      LatLng eLalLng = new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
//      hodler.itemTvNearDistance.setText(MapUtils.getDistance(((HomeActivity)context).mMapManager.getLatLng(), eLalLng));
      return View.inflate(getActivity(), R.layout.item_dynamic_item, null);
    }
  }
}
